//
//  YZActionSheetCell.h
//  VET
//
//  Created by YZ on 2018/7/10.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZActionSheetCell.h"

@implementation YZActionSheetCell
{
    CGFloat _height;
    YZActionSheetStyle _style;
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.coverView = [[UIView alloc] init];
        self.coverView.backgroundColor = kColorWithHex(0xFFFFFF);
        [self addSubview:_coverView];
    }
    return self;
}

- (void)setupYZActionSheetDefaultCellWithTitle:(NSString *)title CellHeight:(CGFloat)height
{
    _style = YZActionSheetDefault;
    _height = height;
    _coverView.frame = CGRectMake(0, 0, kScreenWidth, _height);
    
    self.titleLab = [[UILabel alloc] init];
    _titleLab.frame = CGRectMake(0, 0, kScreenWidth, _height);
    _titleLab.textAlignment = NSTextAlignmentCenter;
    _titleLab.text = title;
    [self.coverView addSubview:_titleLab];
    
    self.bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, _height-0.5, kScreenWidth, 0.5)];
    _bottomLine.backgroundColor = [UIColor grayColor];
    [self.coverView addSubview:_bottomLine];
    
}
- (void)setupYZActionSheetIconAndTitleWithTitle:(NSString *)title titleFont:(UIFont *)font icon:(UIImage *)icon cellHeight:(CGFloat)height
{
    _style = YZActionSheetIconAndTitle;
    _height = height;
    _coverView.frame = CGRectMake(0, 0, kScreenWidth, _height);
    
    NSDictionary *attrs = @{NSFontAttributeName:font};
    CGSize size = [title sizeWithAttributes:attrs];
    CGFloat titleWidth = size.width+10;
    
    self.titleLab = [[UILabel alloc] init];
    _titleLab.frame = CGRectMake((kScreenWidth-titleWidth)/2, 0, titleWidth, _height);
    _titleLab.textAlignment = NSTextAlignmentCenter;
    _titleLab.text = title;
    [self.coverView addSubview:_titleLab];
    
    CGFloat iconWidth = _height*0.4;
    self.iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMinX(_titleLab.frame)-iconWidth-10, _height*0.3, iconWidth, iconWidth)];
    _iconImg.image = icon;
    [self.coverView addSubview:_iconImg];
    
    self.bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, _height-0.5, kScreenWidth, 0.5)];
    _bottomLine.backgroundColor = [UIColor grayColor];
    [self.coverView addSubview:_bottomLine];
}

- (void)setupYZActionSheetLeftTextAndRightImgWithTitle:(NSString *)title titleFont:(UIFont *)font img:(UIImage *)img cellHeight:(CGFloat)height
{
    _style = YZActionSheetLeftTextAndRightImg;
    _height = height;
    _coverView.frame = CGRectMake(0, 0, kScreenWidth, _height);
    
    NSDictionary *attrs = @{NSFontAttributeName:font};
    CGSize size = [title sizeWithAttributes:attrs];
    CGFloat titleWidth = size.width+10;
    
    self.titleLab = [[UILabel alloc] init];
    _titleLab.frame = CGRectMake(kCurrentDeviceNum(20), 0, titleWidth, _height);
    _titleLab.textAlignment = NSTextAlignmentLeft;
    _titleLab.text = title;
    _titleLab.textColor = kColorWithHex(0x393939);
    [self.coverView addSubview:_titleLab];
    
    self.iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - kCurrentDeviceNum(20) - kCurrentDeviceNum(14),_height/2-kCurrentDeviceNum(5), kCurrentDeviceNum(14), kCurrentDeviceNum(10))];
    _iconImg.image = img;
    _iconImg.hidden = YES;
    [self.coverView addSubview:_iconImg];
    
    self.bottomLine = [[UIView alloc] initWithFrame:CGRectMake(kCurrentDeviceNum(20), _height-0.5, kScreenWidth - kCurrentDeviceNum(20), 0.5)];
    _bottomLine.backgroundColor = kColorWithHex(0xD9D9D9);
    [self.coverView addSubview:_bottomLine];
}

- (void)setupYZActionSheetIconAndTitleWithIcon:(UIImage *)icon
                                    cellHeight:(CGFloat)height
{
    _style = YZActionSheetIcon;
    _height = height;
    _coverView.frame = CGRectMake(0, 0, kScreenWidth, _height);
    
    CGFloat iconWidth = _height*0.4;
    
    self.iconImg = [[UIImageView alloc] initWithFrame:CGRectMake((kScreenWidth-iconWidth)/2, _height*0.3, iconWidth, iconWidth)];
    _iconImg.image = icon;
    [self.coverView addSubview:_iconImg];
    
    self.bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, _height-0.5, kScreenWidth, 0.5)];
    _bottomLine.backgroundColor = [UIColor grayColor];
    [self.coverView addSubview:_bottomLine];
}


@end
